import Base from "./Base";
import utils from "src/utils";
import { Props } from "src/types/shape";

export default class extends Base {
    private pointList: Array<object> = []
    constructor(option: any) {
        super()
        utils.object.Assign(option, this.props)
        this.pointList = option.pointList
        this.props.x += this.props.width / 2
        this.props.y += this.props.height / 2
    }
    draw(ctx: CanvasRenderingContext2D, osCtx: OffscreenCanvasRenderingContext2D): void {
        const { width, height } = this.props
        if (!ctx || !osCtx) return

        ctx.save()

        this.transform(ctx)
        ctx.translate(width / 2, height / 2)

        ctx.beginPath()
        this.initOptions(ctx, 1)
        this.pointList.forEach((item: any) => {
            ctx.lineTo(item.x, item.y)
        });
        ctx.stroke()
        ctx.closePath()

        ctx.restore()
        // 镜像画布
        this.drawMirror(osCtx)
    }
    setProps(option: Props): void {
        super.setProps(option)

        this.props.x += this.props.width / 2
        this.props.y += this.props.height / 2
    }
}